package data

import (
	"fmt"

	corev1 "k8s.io/api/core/v1"
)

type SimpleService struct {
	*corev1.Service
}

type SimpleNodesList struct {
	*corev1.NodeList
}

func (r *SimpleNodesList) NodeNameList() (strList []string) {
	strList = make([]string, len(r.Items))

	for i, node := range r.Items {
		strList[i] = node.Name
	}
	return
}

type SimplePodListResult struct {
	*corev1.PodList
	Err error
}

func (r *SimplePodListResult) Error() error {
	return r.Err
}

func (r *SimplePodListResult) ContainerMap() (containerMap map[string]string, err error) {
	if r.Err != nil {
		return nil, r.Err
	}
	containerMap = make(map[string]string)

	for _, pod := range r.Items {
		for _, container := range pod.Spec.Containers {
			name := fmt.Sprint(pod.Name, `_`, container.Name)
			containerMap[name] = pod.Spec.NodeName
		}
	}

	return
}
func (r *SimplePodListResult) ContainerList() (containers []string, err error) {
	if r.Err != nil {
		return nil, r.Err
	}

	for _, pod := range r.Items {
		for _, container := range pod.Spec.Containers {
			containers = append(containers, container.Name)
		}
	}

	return
}

type SimplePod struct {
	*corev1.Pod
}
